home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / D-G / EDITmOR Folder / Reverse case.c < prev   
Encoding:
C/C++ Source or Header  |  1989-07-03  |  2.8 KB  |  84 lines  |  [TEXT/KAHL]

  1. /*EDITmOR version 1.0. © 1989, by Robert S. T. Gibson
  2. Reverse case ECMD:
  3. An external command for EDITmOR (ECMD).
  4.  
  5. Reverse case is a simple routine to reverse the case of the current selection in a
  6. text window. Thanks to Joel McNamara for showing methods for doing so in his
  7. July, 1989 (Vol. 5 No. 7) article ("Extend your Favourite Editor").
  8.  
  9. This is sample source code to display how one would create an ECMD for EDITmOR.
  10.  
  11. Be aware that EDITmOR is subject to updates, which could cause some problems with
  12. some of your ECMDs. Keep your source code so you can easily make changes as to
  13. avoid problems. I will release sample source code, etc. with all future releases.
  14.  
  15. Reverse case project file:
  16. --------------------------
  17. MacTraps
  18. Reverse case.c
  19. --------------------------
  20.  
  21. Reverse case project type:
  22. Code resource
  23. File type: rsrc (if you like... rsrc is ResEdit's files type)
  24. Creator: RSED (if you like... RSED is ResEdit's creator)
  25. Custom Header: No
  26. Name: Reverse case (or rename it if you want)
  27. Type: ECMD (that's -E-DITmOR -C-o-M-man-D-)
  28. ID: whatever
  29. Attrs: 20 (purgeable)
  30.  
  31. That should be about it... Copy the resource into EDITmOR's file and run the DA.
  32. Your command should show up in the menu.
  33.  
  34. Note: If you are using Font/DA Juggler or SuitCase, you will have to close your file
  35. before you can edit it.
  36. If you are not using any such utility, you'll have to edit your System file rather
  37. than just the DA suitcase file.
  38.  
  39. Please distribute this source to show how ECMDs are written... It's fairly simple.
  40. */
  41.  
  42.  
  43. int reverse(c)    /*reverse the case of a character, c*/
  44. char c;
  45. {
  46.     return((c>='A') && (c<='Z') ? (c+32) : ((c>='a') && (c<='z') ? (c-32) : c));
  47.         /*reverse the case of the character (c) and return it*/
  48. } /*end reverse()*/
  49.  
  50.  
  51. pascal Boolean    /*our function must be declared as pascal, for that's what it is called as*/
  52. main()
  53. {
  54.     long    len;
  55.     Handle    myHandle;
  56.     Handle    newHandle;
  57.     long    myOffset;
  58.     long    index;
  59.     
  60.     myHandle = NewHandle(0);    /*get a new handle*/
  61.     len = GetScrap(myHandle, 'TEXT', &myOffset);    /*get length and stuff*/
  62.     
  63.     if (len > 0) /* must be something in the scrap before we can start converting things...*/
  64.         {
  65.             newHandle = NewHandle(GetHandleSize(myHandle));    /*we need a handle to use*/
  66.             
  67.             for (index = 0; index <= GetHandleSize(myHandle); index++)
  68.                 {
  69.                     *(((char *)(*newHandle)) + index) = reverse(*((char *)((long)(*myHandle) + index)));
  70.                         /*index through the handle and reverse each character*/
  71.                 }
  72.             
  73.             ZeroScrap();    /*clear the scrap*/
  74.             PutScrap(GetHandleSize(myHandle), 'TEXT', *newHandle);    /*stick our data there*/
  75.             DisposHandle(newHandle);    /*clean things up a bit*/
  76.             
  77.             return(true);    /*must to return true to have our data pasted in*/
  78.                             /*It's for error checking, by the way, of which there is none above*/
  79.         }
  80.     return(false); /* nothing of type 'TEXT' in the scrap so it does not have to be pasted back in */
  81. } /*end main()*/
  82.  
  83. /*by Robert S. T. Gibson*/
  84.